package com.define.commons.demo.controller;

import com.define.commons.demo.domain.User;
import com.define.commons.redis.client.RedisClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试的controller
 * @Author: liguocheng
 * @Date: 2018/12/4 15:39
 */
@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private RedisClient redisClient;

    @PostMapping
    String saveUser() {
        User user1 = new User();
        user1.setName("啦啦啦");
        user1.setAge(30);
        user1.setSex("女");
        redisClient.set("user1", user1);
       Map<String, Object> map1 = new HashMap<>();
        map1.put("map",user1);
        redisClient.hmSet("map","map1",map1);
        return "保存成功";
    }

    @PostMapping("/save")
    String save(@RequestParam("key") String key,@RequestParam("value") String value) {
        redisClient.set(key, value);
        return "保存成功";
    }

    @GetMapping
    Object getUser(@RequestParam("key") String key) {

        return redisClient.get(key);
    }
    @GetMapping("/get")
    Object getHash(@RequestParam("key") String key,@RequestParam("hash") Object hash) {

        return redisClient.hmGet(key,hash);
    }

    @DeleteMapping
    String delete(@RequestParam("key") String key,@RequestParam("hash") Object hash) {

        redisClient.hmDel(key,hash);
        return "删除成功";
    }
    @RequestMapping("/aa")
    String test(){

        return "请求成功";
    }
}
